GBML manual / Maps

map_has

True if key is currently present in target, false otherwise. The way to know, BEFORE calling map_get, whether the value it would give back is real or just the missing-key default.

Syntax

map_has(target, key) -> bool

Arguments

NameType
targetmap
keymapkey

Returns

bool

Description

true if key is currently present in target, false otherwise.

This is the way to know, BEFORE calling map_get, whether the value it would give back is real or just the missing-key default.

Example

/// @type {map<string,int>}
var scores = {};
map_set(scores, "alice", 10);
var has_alice = map_has(scores, "alice"); // true
var has_bob = map_has(scores, "bob"); // false
A real capture - the map holding alice - 10, and HAS alice? answering YESA real capture - the map holding alice - 10, and HAS alice? answering YES
A real capture - the map holding alice - 10, and HAS alice? answering YES
The same map, unchanged - HAS bob? answering NO, since bob was never setThe same map, unchanged - HAS bob? answering NO, since bob was never set
The same map, unchanged - HAS bob? answering NO, since bob was never set

On the GBA

Just the hash map's contains() - O(1) average.

See also: map_getmap_setmap_removemap_lengthData containers